


float4x4 g_projMatrix : PROJ;
float4x4 g_viewMatrix : VIEW;
float4x4 g_worldMatrix : WORLD;

float4 g_matAmbient : MATERIALAMBIENT;
float4 g_matDiffuse : MATERIALDIFFUSE;

float4 g_lightAmbient : LIGHTAMBIENT;
float4 g_lightDiffuse : LIGHTDIFFUSE;
float3 g_lightPosition : LIGHTPOSITION;

texture g_texDiffuse : TEXTUREDIFFUSE;


sampler2D g_samDiffuse = 
sampler_state
{
	Texture = <g_texDiffuse>;
	MinFilter = Linear;
	MagFilter = Linear;
	MipFilter = Linear;
};

struct VS_OUTPUT
{
	float4 position : POSITION;
	float2 txt      : TEXCOORD0;
	float3 lightDir : TEXCOORD1;
	float3 normal	: TEXCOORD2;
};

struct PS_OUTPUT
{
	float4 color : COLOR0;
};

VS_OUTPUT MyVS(float4	pos		: POSITION,
			   float4   normal	: NORMAL,
			   float2   txt		: TEXCOORD0,
			   uniform float4x4 worldViewProjMatrix)
{
	VS_OUTPUT output;

	output.position = mul (pos, worldViewProjMatrix);

	float3 position = mul (pos, g_worldMatrix).xyz;
	output.normal = mul (float4(normal.xyz, 0.0), g_worldMatrix).xyz;

	output.lightDir = g_lightPosition - position;
	output.txt = txt;
	return output;
}


PS_OUTPUT MyPS(VS_OUTPUT input)
{
	PS_OUTPUT output;
	output.color = g_matAmbient * g_lightAmbient;
	float4 diff = tex2D (g_samDiffuse, input.txt);

	float f = dot (normalize(input.normal), normalize(input.lightDir));
	if (f > 0.0)
	{
		output.color = output.color + g_matDiffuse * g_lightDiffuse * f;
	}
	output.color = output.color * diff;
	return output;
}

technique TestTechnique
{
	pass P0
	{
		VertexShader = compile vs_2_0 MyVS(mul(g_worldMatrix, mul (g_viewMatrix, g_projMatrix)));
		PixelShader  = compile ps_2_0 MyPS();
	}
}